<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/usercenter/center.css">
    <script src="../js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var account = window.sessionStorage.getItem("account");
            //页面打开后,自动向servlet发送请求 查询用户个人信息
            $.get("../login/findUserMsg", {account: account}, function (res) {
                console.log(res);
                $("input[name='account']").val(res.data.account)
            }, "json");
        })

        //判断原密码是否正确
        function judgePwd() {
            $.post("../login/checkPwd", $("#formId1").serialize(), function (res) {
                if (res.code == 200) {
                    $("#oldId").html(res.msg)
                } else if (res.code == 201) {
                    $("#oldId").html(res.msg)
                } else {
                    alert(res.msg);
                }
            });
        }
        //判断新密码长度是否合格
        function checkNum(){
            if($("#newPwdId").val().length<6){
                $("#new1Id").html("密码最少输入六位")
            }else {
                $("#new1Id").html("√")
            }
        }
        //查询新密码输入是否与确认输入密码相同
        function check(){
            if($("#newPwdId").val()===$("#pwd").val()){
                $("#new2Id").html("√");
            }else {
                $("#new2Id").html("密码不一致，请重新输入");
            }
        }

        //修改密码
        function update() {
            $.post("../login/updatePwd", $("#formId2").serialize(), function (res) {
               console.log(res)
                if(res.code==200){
                    alert(res.msg);
                }else {
                    alert(res.msg);
                }

            });
        }
    </script>
</head>
<body>
<div class="public_m1">
    <div class="public_m2">账户安全</div>
    <!--照片和内容-->
    <div class="zp_nrm">
        <!--left-->
        <div class="zp_nrm_l">
            <img src="../img/usercenter/user.png">
        </div>
        <!--right-->
        <form id="formId1">
            <input type="hidden" id="accountId" name="account"/>
            <!--查询原密码是否正确-->
            <div class="zp_nrm_r">
                <p><em>账号：</em><input type="text" name="account" disabled></p>
                <p><em>原密码：</em><input type="text" name="password" onblur="judgePwd()"><span id="oldId"></span></p>
            </div>
        </form>
        <form id="formId2">
            <!--修改密码  确认密码输入是否一致-->
            <div class="zp_nrm_r">
                <p>新密码：<input type="text" id="newPwdId" onblur="checkNum()"><span id="new1Id"></span></p>
                <p>确认密码：<input type="text" name="password" id="pwd" onblur="check()"><span id="new2Id"></span></p>
                <a class="public_m3" onclick="update()">修改密码</a>
            </div>
        </form>
    </div>
</div>
</body>
</html>
